package com.java01.file.inputstream;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class FileToString {

	public static String fileToString(File file){
        if(!file.exists()){
            return null;
        }
        
        FileInputStream fis = null;
        DataInputStream dis = null;
        BufferedReader br = null;
        
        StringBuffer content = new StringBuffer();
        try {
            fis = new FileInputStream(file);
            dis = new DataInputStream(fis);
            br = new BufferedReader(new InputStreamReader(dis));
            String strLine;
            while ((strLine = br.readLine()) != null)   {
                content.append(strLine+"\n");
            }
            return content.toString();
        } catch (Exception e) {
            return null;
        }finally{
        	if(fis!=null){
        		try {
					fis.close();
				} catch (IOException e) {}
        	}
        	if(dis!=null){
        		try {
					dis.close();
				} catch (IOException e) {}
        	}
        	if(br!=null){
        		try {
					br.close();
				} catch (IOException e) {}
        	}
        }
    }
	
	public static void main(String[] args) {
		System.out.println(fileToString(new File("d:\\sqlite.sql")));
	}

}
